package com.hhit.zhgd.controller

import com.hhit.zhgd.domain.dto.CakeInfo
import com.hhit.zhgd.domain.entity.ZhgdArchiveSituations
import com.hhit.zhgd.domain.response.BaseResp
import com.hhit.zhgd.service.ZhgdArchiveSituationsService
import org.apache.commons.lang3.StringUtils
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.*
import org.springframework.web.multipart.MultipartFile

@RestController
class ZhgdArchiveSituationsController {

    @Autowired
    private val zhgdArchiveSituationsService: ZhgdArchiveSituationsService? = null


    @PostMapping("importArchivesFile")
    @Throws(Exception::class)
    fun importArchivesFile(@RequestParam("file") multipartFile: MultipartFile?): BaseResp<Any?>? {
        return zhgdArchiveSituationsService?.importArchivesFile(multipartFile)
    }


    @GetMapping("getArchivesFileTree")
    fun getArchivesFileTree(): BaseResp<Any?>? {
        return zhgdArchiveSituationsService?.getArchivesFileTree()
    }

    @PostMapping("editArchivesFile")
    fun editArchivesFile(@RequestBody params: ZhgdArchiveSituations?): BaseResp<Any?>? {
        zhgdArchiveSituationsService?.updateById(params)
        return BaseResp.success()
    }

    @GetMapping("getArchivesFileStatistics")
    fun getArchivesFileStatistics(): BaseResp<Any?>? {
        val list: List<ZhgdArchiveSituations> = zhgdArchiveSituationsService?.list()?: listOf()
        val threeList: List<ZhgdArchiveSituations> =
            list.filter { it.lmh != null && it.lmh.length === 4 }.toCollection(ArrayList())
        var ysczls = 0
        var xtgzls = 0
        for (zhgdArchiveSituations in threeList) {
            if (StringUtils.isNotBlank(zhgdArchiveSituations.fileUrls)) {
                ysczls += 1
            } else {
                xtgzls += 1
            }
        }
        val out: MutableList<CakeInfo> = ArrayList()
        out.add(CakeInfo(name = "已上传资料数", value = ysczls))
        out.add(CakeInfo(name = "需提供资料数", value = xtgzls))
        return BaseResp.success(out)
    }
}